<?php
class AdminnewsController extends Controller {

	public function indexAction() {
		
	}

	public function addnewsAction() {
		$this->checkLoginRedirect();
        $this->setErrors();
		$this->_view->assignArray(array(
			'pageTitle' => 'Localization system :: Add news',
            'pageId' => 'newsadd'
		));
		$this->_view->render('admin/news/add');
	}

	public function runaddnewsAction() {
		$this->checkLoginRedirect();

		$newsItemVisible = ($this->_request->getString('visible') == 'on') ? '1' : '0';
		$newsItemStick = ($this->_request->getString('stick') == 'on') ? '1' : '0';
		$newsItemTitle = $this->_request->getString('title');
		$newsItemText = $this->_request->getString('text');
		if(empty($newsItemTitle)) {
            $this->addError('News item title can not be empty');
        }
        if(empty($newsItemText)) {
            $this->addError('News item text can not be empty');
        }
		if(!$this->isErrors()) {
			$newsItem = new NewsItem();
			$newsItem->setTitle($newsItemTitle);
			$newsItem->setText($newsItemText);
			$newsItem->setSticky($newsItemStick);
			$newsItem->setVisible($newsItemVisible);
			$newsItem->save();
			$this->delegateToAction('addmore');
		}
        else {
            $this->delegateToAction('addnews');
        }
	}

	public function addmoreAction() {
        $this->checkLoginRedirect();
		$this->_view->assignArray(array(
			'pageTitle' => 'Localization system :: Add more?',
            'pageId' => 'morenewssadd'
		));
		$this->_view->render('admin/news/addmore');
	}
}